<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
      layout:decorate="~{admin/layout}">
<body>

<div  class="content-wrap" layout:fragment="content">
    <main id="content" class="content" role="main">
        <ol class="breadcrumb">
            <li>财务管理</li>
            <li class="active">入库管理</li>
        </ol>
        <div class="row mb-lg">
            <div role="tabpanel" class="tab-pane active in clearfix" id="basic" aria-labelledby="basic-tab" aria-expanded="true">
                <div class="widget-body">
                    <!--<button id="submit" class="btn btn-primary" style="background-color: #64bd63;background-color: #64bd63;border-color: #64bd63;">批次生成</button>-->
                    <button id="luru" class="btn btn-primary" style="background-color: #64bd63;background-color: #64bd63;border-color: #64bd63;">录入产地和价格</button>
                    <div class="mt">
                        <div id="priceandlocation" style="display: none">
                            价格: <input type="text" id="price" /><br />
                            产地: <input type="text" id="location" /><br />
                            <input type="submit" id="priceadd">
                        </div>
                        <table   class="table table-striped table-hover">
                            <thead>
                            <tr>
                                <th>
                                    <div class="checkbox abc-checkbox">
                                        <input id="checkbox1" type="checkbox" data-check-all>
                                        <label for="checkbox1"></label>
                                    </div>
                                </th>
                                <th>采购地</th>
                                <th class="hidden-sm-down">采购数量</th>
                                <th class="hidden-sm-down">树种</th>
                                <th class="no-sort">胸径/地径</th>
                                <th class="no-sort">高度</th>
                                <th class="no-sort">冠幅</th>
                                <th class="no-sort">是否丛生</th>
                                <th class="no-sort">枝条数</th>
                                <th class="no-sort">入库时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="tree:${trees}">
                                <td>
                                    <div class="checkbox abc-checkbox">
                                        <input class="cc" th:id="${tree.tree_id}" type="checkbox">
                                        <label th:for="${tree.tree_id}"></label>
                                    </div>
                                </td>
                                <td th:text="${tree.location}" ></td>
                                <td th:text="${tree.number}">100</td>
                                <td class="hidden-sm-down" th:text="${tree.treeSpecies}"></td>
                                <td class="hidden-sm-down check" th:text="${tree.chestBreadth}"></td>
                                <td class="hidden-sm-down check" th:text="${tree.height}"></td>
                                <td class="hidden-sm-down check" th:text="${tree.crownWidth}"></td>
                                <td class="hidden-sm-down check" th:switch="${tree.clump}">
                                    <span th:case="true">丛生</span>
                                    <span th:case="false">&nbsp;</span>
                                </td>
                                <td class="hidden-sm-down check" th:text="${tree.salenumber}"></td>
                                <td class="hidden-sm-down" th:text="*{#dates.format(tree.createtime,'yyyy-MM-dd')}"></td>
                            </tr>
                            </tbody>
                        </table>
                        <script>
                            checknumber();
                            $(function () {
                                $("#submit").click(function () {
                                    var str="";
                                    $(".cc").each(function (i, obj) {
                                        if($(this).is(':checked')){
                                            str=str+($(this).attr("id")+";");
                                        }
                                    })
                                    console.log(str);
                                    $.ajax({
                                        url: "/api/batch/generate",
                                        type: 'POST',
                                        data:{"treeids":str},
                                        async: false,
                                        success: function (data) {
                                            console.log(data);
                                            location.reload();
                                        },
                                        error: function (xhr) {
                                            console.log("error")
                                        }
                                    });
                                })
                                $("#luru").click(function () {
                                    $("#priceandlocation").toggle();
                                    console.log("log");
                                    $("#priceadd").click(function(){
                                        var str="";
                                        $(".cc").each(function (i, obj) {
                                            if($(this).is(':checked')){
                                                str=str+($(this).attr("id")+";");
                                            }
                                        });
                                        if(str==""){
                                            alert('请选择需要录入行！')
                                        }else{
                                            var price=$("#price").val();
                                            var location=$("#location").val();
                                            $.ajax({
                                                url: "/api/batch/update",
                                                type: 'POST',
                                                data:{"treeids":str,"price":price,"location":location},
                                                async: false,
                                                success: function (data) {
                                                    console.log(data);
                                                    window.location.reload();
                                                },
                                                error: function (xhr) {
                                                    console.log(xhr);
                                                    $("#priceandlocation").hide();
                                                }
                                            });
                                        }
                                    });
                                })
                            });
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </main>
</div>
</body>
</html>